package com.warmheart.core.cors.builder;

import java.util.List;
import java.util.Map;

import com.warmheart.core.co.builder.CoBuilder;
import com.warmheart.core.co.model.OrderByModel;
import com.warmheart.core.co.model.RelationModel;
import com.warmheart.core.combine.model.CombineModel;
import com.warmheart.core.combine.model.JoinModel;
import com.warmheart.core.combine.oper.Combine;
import com.warmheart.core.rs.builder.RsBuilder;
import com.warmheart.core.rs.model.DistinctModel;
import com.warmheart.core.rs.model.SelectedModel;

/**
 * 
 * @ClassName: CoRsBuilder
 * @Description: 自定义查询条件、排序、返回值顶级接口，实现该接口的对象存在自定义查询条件、排序、返回值的可能
 * @author ZhangJianyang
 * @date 2025-06-16 09:37:02
 *
 * @param <E>
 * @param <R>
 */
public interface CoRsBuilder<E extends CoBuilder<?>, R extends RsBuilder<?>> {
    
    /**
     * 
     * @Title: tableName
     * @Description: 表名称
     * @author ZhangJianyang
     * @return
     */
    public String tableName();

    /**
     * 
     * @Title: getCombineModel
     * @Description: 联合模型
     * @author ZhangJianyang
     * @return
     */
    public CombineModel getCombineModel();

    /**
     * 
     * @Title: combine
     * @Description: 多表联合
     * @author ZhangJianyang
     * @param joins
     * @return
     */
    default Combine combine() {
        CombineModel currCombineModel = getCombineModel();
        final List<CoRsBuilder<?, ?>> joinList = currCombineModel.getJoinList();
        final Map<CoRsBuilder<?, ?>, String> joinAliasMap = currCombineModel.getJoinAliasMap();
        final Map<String, CoRsBuilder<?, ?>> aliasJoinMap = currCombineModel.getAliasJoinMap();
        int i = joinList.size();
        if (joinAliasMap.get(this) == null) {
            String alias = "t" + (i > 0 ? i : "");
            joinAliasMap.put(this, alias);
            aliasJoinMap.put(alias, this);
            joinList.add(this);
        }
        return new Combine(joinList, joinAliasMap, aliasJoinMap);
    }

    /**
     * 
     * @Title: getJoinModel
     * @Description: 联合关系模型
     * @author ZhangJianyang
     * @return
     */
    public JoinModel getJoinModel();

    /**
     * 
     * @Title: coBuilder
     * @Description: 自定义查询条件、排序构造器
     * @author ZhangJianyang
     * @return
     */
    public E coBuilder();

    /**
     * 
     * @Title: getRelationModelList
     * @Description: 关系模型列表
     * @author ZhangJianyang
     * @return
     */
    public List<RelationModel> getRelationModelList();

    /**
     * 
     * @Title: getOrderByModelList
     * @Description: 排序模型列表
     * @author ZhangJianyang
     * @return
     */
    public List<OrderByModel> getOrderByModelList();

    /**
     * 
     * @Title: rsBuilder
     * @Description: 自定义返回值构造器
     * @author ZhangJianyang
     * @return
     */
    public R rsBuilder();

    /**
     * 
     * @Title: getDistinctModel
     * @Description: 重复过滤处理
     * @author ZhangJianyang
     * @return
     */
    public DistinctModel getDistinctModel();

    /**
     * 
     * @Title: getSelectedModelList
     * @Description: 自定义返回值列表
     * @author ZhangJianyang
     * @return
     */
    public List<SelectedModel> getSelectedModelList();
}
